//
//  InvitationOptionsViewController.m
//  nonghubao
//
//  Created by Fenrir on 13-5-28.
//  Copyright (c) 2013年 Chongqing Nonghubao Co., Ltd. All rights reserved.
//

#import "InvitationOptionsViewController.h"
#import "Helper.h"
#import "Config.h"
#import "ABInvitationViewController.h"
#import "MobileInvitationViewController.h"
#import "PlatformInvitationViewController.h"

//  -业务逻辑细节说明-
//
//  @abstract      此VC并无业务逻辑
//

//  @discussion

//  @notes          


//  -类修改日志-
//  修改人   修改时间   针对版本
//  修改描述
@interface InvitationOptionsViewController ()

@end

@implementation InvitationOptionsViewController
@synthesize circle = _circle;
@synthesize backMode = _backMode;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
        _backMode = NO;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = _L(@"vc_title_101");
    
    UIButton *backButton = [Helper buttonWithStyle:ButtonStyleNavigationReturn];
    [backButton addTarget:self action:@selector(backButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 5.0f, 200.0f, 25.0f)];
    titleLabel.font = _SYS_FONT_004;
    titleLabel.text = _L(@"title_invite_03");
    [self.view addSubview:titleLabel];
    
    //分割线或转账申请处理中提示
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, titleLabel.frame.origin.y + titleLabel.frame.size.height, 320.0f, 0.5f)];
    
    lineView.backgroundColor = [UIColor colorWithRed:219.0f/255.0f green:219.0f/255.0f blue:219.0f/255.0f alpha:1.0f];
    [self.view addSubview:lineView];

    UIButton *firstButton = [self createButtonWithFrame:CGRectMake(10.0f, lineView.frame.origin.y + lineView.frame.size.height + 5.0f, 300.0f, 45.0f) andImage:@"dynamic_icon_006@2x" andLabel:[NSString stringWithFormat:_L(@"title_invite_06"), _L(@"vc_title_001")]];
    
    firstButton.tag = 1;
    [self.view addSubview:firstButton];
    
    lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, firstButton.frame.origin.y + firstButton.frame.size.height + 5.0f, 320.0f, 0.5f)];
    lineView.backgroundColor = [UIColor colorWithRed:219.0f/255.0f green:219.0f/255.0f blue:219.0f/255.0f alpha:1.0f];
    [self.view addSubview:lineView];
    
    
    UIButton *secondButton = [self createButtonWithFrame:CGRectMake(10.0f, lineView.frame.origin.y + lineView.frame.size.height + 5.0f, 300.0f, 45.0f) andImage:@"dynamic_icon_004@2x" andLabel:_L(@"title_invite_04")];
    secondButton.tag = 2;
    [self.view addSubview:secondButton];
    
    
    lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, secondButton.frame.origin.y + secondButton.frame.size.height + 5.0f, 320.0f, 0.5f)];
    lineView.backgroundColor = [UIColor colorWithRed:219.0f/255.0f green:219.0f/255.0f blue:219.0f/255.0f alpha:1.0f];
    [self.view addSubview:lineView];
    
    UIButton *threeButton = [self createButtonWithFrame:CGRectMake(10.0f, lineView.frame.origin.y + lineView.frame.size.height + 5.0f, 300.0f, 45.0f) andImage:@"dynamic_icon_005@2x" andLabel:_L(@"title_invite_05")];

    threeButton.tag = 3;
    [self.view addSubview:threeButton];
    
    
    lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, threeButton.frame.origin.y + threeButton.frame.size.height + 5.0f, 320.0f, 0.5f)];
    lineView.backgroundColor = [UIColor colorWithRed:219.0f/255.0f green:219.0f/255.0f blue:219.0f/255.0f alpha:1.0f];
    [self.view addSubview:lineView];
}

#pragma mark - 私有方法

/*!
 @abstract 通过frame、image和label创建自定义button
 @param frame 按钮的frame属性
 @param imageName 按钮上要显示的图片名
 @param label 按钮上要显示提示文字
 @result 自定义UIButton，包含图片和文字。
 */
- (UIButton *)createButtonWithFrame:(CGRect)frame andImage:(NSString *)imageName andLabel:(NSString *)label
{
    UIButton *button = [[UIButton alloc] initWithFrame:frame];
    [button addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 5.0f, 35.5f, 35.0f)];
    imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]];
    [button addSubview:imageView];
    
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageView.frame.origin.x + imageView.frame.size.width + 10.0f, 10.0f, 200.0f, 25.0f)];
    titleLabel.text = label;
    titleLabel.font = _SYS_FONT_005;
    titleLabel.backgroundColor = [UIColor clearColor];
    [button addSubview:titleLabel];
    
    UIImageView *indicator = [[UIImageView alloc] initWithFrame:CGRectMake(320.0f - 30.0f, 15.0f, 9.5f, 16.0f)];
    indicator.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_icon_008@2x" ofType:@"png"]];
    [button addSubview:indicator];
    
    return button;
}

#pragma mark - 自定义事件

/*!
 @abstract 返回按钮事件
 */
- (void)backButtonEvent:(id)sender
{
    if (_backMode) {
        [self.navigationController dismissModalViewControllerAnimated:YES];
        return;
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}

/*!
 @abstract 邀请好友方式按钮事件，被点击的按钮tag为1，即用户点击了“从通讯录添加”按钮，否则就是用户点击了“输入手机号码添加”按钮
 */
- (void)buttonEvent:(id)sender
{
    UIButton *clickedButton = (UIButton *)sender;
    
    //已安装农户宝的好友
    if (clickedButton.tag == 1) {
        
        PlatformInvitationViewController *platformInvitationVC = [[PlatformInvitationViewController alloc] init];
        [self.navigationController pushViewController:platformInvitationVC animated:true];

    }
    
    //在通讯录中的好友
    else if (clickedButton.tag == 2){
        ABInvitationViewController* addressBookViewController = [[ABInvitationViewController alloc] initWithStyle:UITableViewStylePlain];

        [self.navigationController pushViewController:addressBookViewController animated:true];
    }
    
    //输入手机号码添加
    else if (clickedButton.tag == 3) {
        MobileInvitationViewController *mobileInvitationVC = [[MobileInvitationViewController alloc] init];
        [self.navigationController pushViewController:mobileInvitationVC animated:true];
    }
    
    else {
        
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
